<template>
  <div>
    <el-dialog
      :before-close="cancel"
      :title="info.isAdd ? '会员管理' : '会员管理'"
      :visible.sync="info.isShow"
      center
    >
      <el-form ref="manger" :model="mangerinfo" :rules="rules">
       
        <el-form-item  label="编号" :label-width="formLabelWidth">
          <el-input v-model="mangerinfo.uid" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item  label="会员名称" :label-width="formLabelWidth">
          <el-input v-model="mangerinfo.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item  label="电话" :label-width="formLabelWidth">
          <el-input v-model="mangerinfo.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input v-model="mangerinfo.password" autocomplete="off"></el-input>
          <p>留空则是不修改</p>
        </el-form-item>

        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-switch
            v-model="mangerinfo.status"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="2"
          ></el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button @click="confirm" type="primary">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { memberedit, memberinfo, } from "../../request/api";
import { mapActions } from "vuex";
export default {
  data() {
    return {
      mangerinfo: {
        uid: 0,//会员编号
        nickname: "", //管理员名称
        phone:"",//手机号
        password: "", //密码
        status: 1 //状态1正常2禁用
      },
      formLabelWidth: "120px",
      rules: {
        nickname: [
          { required: true, message: "请输入会员名称", trigger: "blur" },
          { min: 2, max: 8, message: "长度在 2 到 8 个字符", trigger: "blur" }
        ],
        roleid: [{ required: true, message: "请选择角色", trigger: "change" }]
      }
    };
  },
  props: ["info"],
  methods: {
    ...mapActions({
      getMember: "member/getMemberListAction",
    }),
    //关闭弹窗方法
    cancel() {
      this.$emit("cancel", false);
      //重置
      this.reset();
    },
    //清空表单内容以及相关验证
    reset() {
      this.mangerinfo = {
        uid: 0,//会员编号
        nickname: "", //管理员名称
        phone:"",//手机号
        password: "", //密码
        status: 1 //状态1正常2禁用
      };
    },
    //查询数据
    lookup(uid) {
      memberinfo({uid}).then(res => {
        if (res.code == 200) {
          this.mangerinfo = res.list;
          this.mangerinfo.uid = uid;
          this.mangerinfo.password = "";
        }
      });
    },
    //确定事件
    confirm() {
      //验证
      this.$refs.manger.validate(val => {
        if (val) {
            //调用编辑接口
            memberedit(this.mangerinfo).then(res => {
              if (res.code == 200) {
                this.$message.success(res.msg);
                this.cancel();
                this.getMember();
              } else {
                this.$message.error(res.msg);
              }
            });

        } else {
          console.log("验证失败");
        }
      });
    }
  }
};
</script>

<style scoped>
</style>
